package ycl.system.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import ycl.common.base.mapper.BaseDao;
import ycl.system.entity.SysAdmin;
import ycl.system.entity.SysUser;

/**
 * <p>
 * 用户表 Mapper 接口
 * </p>
 *
 * @author ycl
 * @since 2022-03-03 11:43:57
 */
@Mapper
@Repository
public interface SysAdminMapper extends BaseDao<SysAdmin> {

	/**
	 * 根据用户名查询用户所有数据
	 *
	 * @param username 用户名
	 * @return 用户
	 */
	@Select("select * from sys_user where username = #{username} limit 1")
	SysUser selectByUsername(@Param("username") String username);

	@Select("select * from sys_user where wechat_id = #{wechatId} limit 1")
	SysUser selectByWechatId(String wechatId);

	/**
	 * 根据手机号查询用户所有数据
	 *
	 * @param mobile 手机号
	 * @return 用户
	 */
	@Select("select * from sys_user where mobile = #{mobile} limit 1")
	SysUser selectByMobile(@Param("mobile") String mobile);


	/**
	 * 根据用户id查询用户的类型
	 *
	 * @param id 用户id
	 * @return 用户类型
	 */
	@Select("select type from sys_user where id = #{id}")
	Integer selectTypeById(Long id);

	@Select("select count(*) > 0 from sys_user where username = #{username} limit 1")
	boolean selectExistByUsername(String username);

	@Select("select count(*) > 0 from sys_user where mobile = #{mobile} limit 1")
	boolean selectExistByMobile(String mobile);

	@Select("select count(*) > 0 from sys_user where id_card = #{idCard} limit 1")
	boolean selectExistByIdCard(String idCard);

	@Select("select count(*) > 0 from sys_user where invitation_code = #{invitation} limit 1")
	boolean selectExistByInvitationCode(String invitation);

	@Select("select count(*) > 0 from sys_user where wechat_id = #{wechatId} limit 1")
	boolean selectExistByWechatId(String wechatId);

	/**
	 * 修改用户登录信息
	 * @param id id
	 * @param token token
	 * @param ip ip
	 */
	void updateLoginDetail(@Param("id") Long id, @Param("token") String token, @Param("ip") String ip);


}
